package com.slg.android.manyanime.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.slg.android.manyanime.MyCollectionActivity;
import com.slg.android.manyanime.MyCommentActivity;
import com.slg.android.manyanime.R;
import com.slg.android.manyanime.bean.User;
import com.slg.android.manyanime.utils.DataStore;

public class UserFragment extends Fragment implements View.OnClickListener {

    private User  user;


    public UserFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View ret = inflater.inflate(R.layout.fragment_user, container, false);
        View view = ret.findViewById(R.id.user_fragment_my_comment);
        View collection = ret.findViewById(R.id.user_fragment_my_collection);
        view.setOnClickListener(this);
        collection.setOnClickListener(this);
        user = DataStore.getDataStore().getUser();

        return ret;
    }



    @Override
    public void onDetach() {
        super.onDetach();
    }


    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id){
            case R.id.user_fragment_my_comment:
                if(user!= null) {
                    Intent intent = new Intent(getActivity(), MyCommentActivity.class);
                    startActivity(intent);
                }else {
                    Toast.makeText(getActivity(),"亲，您还没有登录",Toast.LENGTH_LONG).show();
                }
                break;
            case R.id.user_fragment_my_collection:

//                if(user!= null) {
                    Intent intent = new Intent(getActivity(), MyCollectionActivity.class);
                    startActivity(intent);
//                }else {
//                    Toast.makeText(getActivity(),"亲，您还没有登录",Toast.LENGTH_LONG).show();
//                }
                break;
        }
    }
}
